package wang.j100.uc.module.system.dal.mysql.social;

import wang.j100.uc.framework.common.pojo.PageResult;
import wang.j100.uc.framework.mybatis.core.mapper.BaseMapperX;
import wang.j100.uc.framework.mybatis.core.query.LambdaQueryWrapperX;
import wang.j100.uc.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO;
import wang.j100.uc.module.system.dal.dataobject.social.SubSocialUserDO;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface SocialUserMapper extends BaseMapperX<SubSocialUserDO> {

    default SubSocialUserDO selectByTypeAndCodeAnState(Integer type, String code, String state) {
        return selectOne(SubSocialUserDO::getType, type,
                SubSocialUserDO::getCode, code,
                SubSocialUserDO::getState, state);
    }

    default SubSocialUserDO selectByTypeAndOpenid(Integer type, String openid) {
        return selectFirstOne(SubSocialUserDO::getType, type,
                SubSocialUserDO::getOpenid, openid);
    }

    default PageResult<SubSocialUserDO> selectPage(SocialUserPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SubSocialUserDO>()
                .eqIfPresent(SubSocialUserDO::getType, reqVO.getType())
                .likeIfPresent(SubSocialUserDO::getNickname, reqVO.getNickname())
                .likeIfPresent(SubSocialUserDO::getOpenid, reqVO.getOpenid())
                .betweenIfPresent(SubSocialUserDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SubSocialUserDO::getId));
    }

}
